home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / setState.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.8 KB  |  214 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  13 April 1997
  22. // Author:         jb
  23. //
  24. //
  25. //<doc>
  26. //<name setState>
  27. //<owner "Alias|Wavefront Unsupported">
  28. //
  29. //<synopsis>
  30. //        setState( string $type, int $state )
  31. //
  32. //<returns>
  33. //        None.
  34. //
  35. //<description>
  36. //        Sets the nodeState attr for all nodes in the
  37. //        scene that match the type passed in.
  38. //<P>
  39. //  Note that setting the state for certain types of nodes
  40. //    can have unpredictable results (things will stop building,
  41. //    evaluating, etc, and it can be difficult to determine
  42. //    what is happening in the scene in certain complex cases).
  43. //    Use this mainly for things like expressions, etc.
  44. //
  45. //<flags>
  46. //        string $type : type of node to operate on.
  47. //            valid choices are: iksolver, constraint, expression, particle,
  48. //            rigidbody, snapshot or "all", which will do all of the above.
  49. //
  50. //        int $state : state to set for the node.
  51. //            "off" will turn the node off ("blocking" mode),
  52. //            and "on" will turn the node on ("normal" mode).
  53. //
  54. //<examples>
  55. //  setState "expression" on;
  56. //
  57. //</doc>
  58.  
  59. proc setStates( string $typeList[], int $state, string $stateAttr,
  60.                 int $on, int $off, int $preOn)
  61. {
  62.     string $node;
  63.     string $type;
  64.     string $nodes[];
  65.     
  66.     for ( $type in $typeList ) {
  67.         string $cmd = "ls -type " + $type;
  68.  
  69.         if ( 0 == catch( $nodes = `eval $cmd` ) ) {
  70.             for ( $node in $nodes ) {
  71.                 if ( $state ) {
  72.                     if ( $preOn != $on ) {
  73.                         setAttr ( $node + $stateAttr ) $preOn;
  74.                     }
  75.                     setAttr ( $node + $stateAttr ) $on;
  76.                 } else {
  77.                     setAttr ( $node + $stateAttr ) $off;
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }    
  83.  
  84.     
  85.  
  86. global proc setState( string $type, int $state )
  87. {
  88.     string $nodes[];
  89.     switch( $type ) {
  90.         case "all":
  91.             setState "constraint" $state;
  92.             setState "expression" $state;
  93.             setState "fluid" $state;
  94.             setState "globalstitch" $state;
  95.             setState "iksolver" $state;
  96.             setState "particle" $state;
  97.             setState "rigidbody" $state;
  98.             setState "snapshot" $state;
  99.             break;
  100.         case "iksolver":
  101.             ikSystem -e -sol $state;
  102.  
  103.             // update the checkBox status in Skeleton menu.
  104.             //
  105.             if( `menuItem -exists globalSolveEnableItem` ) {
  106.                 catch(`menuItem -e -cb $state globalSolveEnableItem`);
  107.             }
  108.             break;
  109.         case "constraint":
  110.             string $twoOffConstraints[] = { "pointConstraint",
  111.                                             "aimConstraint",
  112.                                             "orientConstraint",
  113.                                             "parentConstraint",                                            
  114.                                             "scaleConstraint",
  115.                                             "normalConstraint",
  116.                                             "tangentConstraint " };
  117.             setStates( $twoOffConstraints, $state, ".nodeState", 0, 2, 2 );
  118.  
  119.             string $oneOffConstraints[]  = { "geometryConstraint" };
  120.             setStates( $oneOffConstraints, $state, ".nodeState", 0, 1, 1 );
  121.  
  122.             break;
  123.         case "expression":
  124.             $nodes = `ls -type expression`;
  125.             for( $node in $nodes )
  126.             {
  127.                 if( $state ) {
  128.                     setAttr ( $node + ".nodeState" ) 1;
  129.                     setAttr ( $node + ".nodeState" ) 0;
  130.                 } else {
  131.                     setAttr ( $node + ".nodeState" ) 2;
  132.                 }
  133.  
  134.                 // Expressions sometimes have intervening unit conversion
  135.                 // nodes, so make sure they get the same blocked/normal
  136.                 // state as the expression driving them.
  137.                 //
  138.                 string $units[] = `listConnections
  139.                     -skipConversionNodes 0
  140.                     -source 0 -destination 1
  141.                     ($node+".output")`;
  142.                 for ($unit in $units)
  143.                 {
  144.                     if ((nodeType($unit) == "unitConversion") ||
  145.                         (nodeType($unit) == "timeToUnitConversion") ||
  146.                         (nodeType($unit) == "unitToTimeConversion"))
  147.                     {
  148.                         if( $state ) {
  149.                             setAttr ( $unit + ".nodeState" ) 1;
  150.                             setAttr ( $unit + ".nodeState" ) 0;
  151.                         } else {
  152.                             setAttr ( $unit + ".nodeState" ) 2;
  153.                         }
  154.                     }
  155.                 }
  156.             }
  157.             break;
  158.         case "fluid":
  159.             $nodes = `ls -type fluidShape`;
  160.                 for( $node in $nodes ) {
  161.                     if ($state) {
  162.                         setAttr ( $node + ".disableInteractiveEval" ) 0;
  163.                     } else {
  164.                         setAttr ( $node + ".disableInteractiveEval" ) 1;
  165.                     }
  166.                 }
  167.             break;
  168.         case "globalstitch":
  169.             if ($state) {
  170.                 performanceOptions -disableStitch off;
  171.             } else {
  172.                 performanceOptions -disableStitch on;
  173.             }
  174.             break;
  175.         case "particle":
  176.             if( `isTrue DynamicsExists` ) {
  177.  
  178.                 $nodes = `ls -type particle`;
  179.                 for( $node in $nodes ) {
  180.                     if ($state) {
  181.                         setAttr ( $node + ".isDynamic" ) 1;
  182.                     } else {
  183.                         setAttr ( $node + ".isDynamic" ) 0;
  184.                     }
  185.                 }
  186.              }
  187.             break;
  188.         case "rigidbody":
  189.             if( `isTrue DynamicsExists` ) {
  190.                 $nodes = `ls -type rigidSolver`;
  191.                 for( $node in $nodes ) {
  192.                     if ($state) {
  193.                         setAttr ( $node + ".state" ) 1;
  194.                     } else {
  195.                         setAttr ( $node + ".state" ) 0;
  196.                     }
  197.                 }
  198.             
  199.             }
  200.             break;
  201.         case "snapshot":
  202.             $nodes = `ls -type snapshot`;
  203.                 for( $node in $nodes ) {
  204.                     if ($state) {
  205.                         setAttr ( $node + ".nodeState" ) 1;
  206.                         setAttr ( $node + ".nodeState" ) 0;
  207.                     } else {
  208.                         setAttr ( $node + ".nodeState" ) 2;
  209.                     }
  210.                 }
  211.             break;
  212.     }
  213. }
  214.